import React, {Component} from 'react';
import {
  View,
  Text,
  TouchableOpacity,
  Image,
} from 'react-native';

import Config from '../../config';
import SizeUtils from '../../common/SizeUtils';
import ImageConstants from '../../common/ImageConstants';
import {DateUtils} from '../../utils/Utils';
import CommonStyles from '../../common/CommonStyles';
import CommonDataListView from '../common/CommonDataListView';
import BaseItem from '../common/BaseItem';
import BasePage from '../common/BasePage';


export default class CommonListPage extends BasePage {
  constructor(props) {
    super(props);

    this._listView = null;
    this._noEmpty = false;
    this._autoInitRequest = true;
    this._useRefresh = true;
    this._useLoadMore = true;
    this._itemClickEnable = this.props.itemClickEnable === null ? true : this.props.itemClickEnable;
    this._isRowWrap = false;
    this._dataKey = undefined;
  }

  render() {
    return (
      <View style={this._getViewStyle()}>
        {this._renderTopView()}
        <CommonDataListView style={this._getListViewStyle()}
          ref={(ref) => {this._listView = ref}}
          headerHeight={this._getHeader()}
          onPressItem = {this._onPressItem.bind(this)}
          requestData = {this._requestData.bind(this)}
          onRenderItem = {this._onRenderItem.bind(this)}
          onRenderHeader = {this._onRenderHeader.bind(this)}
          onRenderFooter = {this._onRenderFooter.bind(this)}
          noEmpty = {this._noEmpty}
          autoInitRequest = {this._autoInitRequest}
          onScroll = {this._onScroll.bind(this)}
          useRefresh = {this._useRefresh}
          useLoadMore = {this._useLoadMore}
          itemClickEnable = {this._itemClickEnable}
          isRowWrap = {this._isRowWrap}
          dataKey = {this._dataKey}
        />
        {this.props.isInster?null:this._renderNavigationBar()}
        {this._renderBottomView()}
        {this._renderBottomView1()}
        {this._renderShareView()}
      </View>
    )
  }

  _dealEnterPage() {
    super._dealEnterPage();
    this.doRefresh();
  }
  setRefresh(){
    this._listView && this._listView.setRefresh();
  }
  _getHeader(){
    return 0;
  }
  doRefresh() {
    this._listView && this._listView.doRefresh();
  }

  clear() {
    this._listView && this._listView.clear();
  }
  leave() {
    this._listView && this._listView.leave();
  }

  finish(type, data, params) {
    this._listView && this._listView.finish(type, data, params);
  }
  _onScroll(){
    
  }
  _renderTopView() {

  }

  _renderBottomView() {

  }
  _renderBottomView1() {

  }

  _renderChildShareView(){

  }

  _onRenderFooter() {
    if(this.props.onRenderFooter) {
      return this.props.onRenderFooter();
    }
  }

  _getViewStyle() {
    return {paddingTop:this.props.isInster?0:Config.paddingTop + SizeUtils.translateDesignHeightToCode(20),
        backgroundColor:"#ffffff"}
  }

  _getListViewStyle() {
    return {
        width:(SizeUtils.getWindowSize().width - SizeUtils.translateDesignWidthToCode(80)),
        marginLeft:SizeUtils.translateDesignWidthToCode(40),
        height:(SizeUtils.getWindowSize().height - Config.paddingTop - SizeUtils.translateDesignHeightToCode(40)),
        backgroundColor:"#ffffff00"};
  }

  _onRenderHeader() {
    if(this.props.onRenderHeader) {
      return this.props.onRenderHeader();
    }
    else {
      //要不然不显示下拉刷新
      return (
        <View style={{height:1}}>
        </View>
      )
    }
  }

  _onRenderItem(data, index) {

  }

  _onPressItem(data) {

  }

  _requestData(page, listView) {

  }
}
